from flask import Flask, jsonify, render_template
app = Flask(__name__)


@app.route('/')
def index():
    return '<h1>Hello</h1>'

@app.route('/calc/get-result',method='POST')
def calcResult():
    if request.method=='POST':
        result=eval(request.form['command'])
        return '<script>alert({})</script>'.format(str(result))

@app.route('/calc')
def calcUI():
    return '<form action="http://localhost:9000/calc/get-result" method="post">\
    <h1>Calcer</h1>\
    <br>\
    <input type="text" name="command" />\
    <input type="submit" value="Submit to calc" />\
    </form>'
# HTTP 直通函数由于是基于 docker 镜像运行，所以必须监听地址为 0.0.0.0，并且端口为 9000
app.run(host = '0.0.0.0', port = 9000)
